package com.itchen.controller;

import com.itchen.pojo.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author げっしょく
 * @date 2021/9/15
 */
@RestController
@RequestMapping("books")
public class Usercontroller {

    @GetMapping
    public List<Book> selectAll() {
        List<Book> bookList = new ArrayList<Book>();
        Book book1 = new Book();
        book1.setType("计算机");
        book1.setName("SpringMVC入门教程");
        book1.setDescription("小试牛刀");
        bookList.add(book1);

        Book book2 = new Book();
        book2.setType("计算机");
        book2.setName("SpringMVC实战教程");
        book2.setDescription("一代宗师");
        bookList.add(book2);

        return bookList;
    }

    @PostMapping
    public String insert(@RequestBody Book book) {
        System.out.println(book);
        return "success";
    }

    @PutMapping
    public String update(@RequestBody Book book) {
        System.out.println(book);
        return "true";
    }

    @PostMapping("/deleteById")
    public String delete(@RequestBody Book book) {
        System.out.println(book);
        return "delete success";
    }
}
